<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<script src="./10-promise.js"></script>
<script>

let p1 = new Promise((resolve,reject)=>{// excutor执行器函数
    console.log( '执行器函数...' );
    setTimeout(function (){
        resolve(123);// 修改为成功状态
        // reject(456);// 修改为失败状态
    },1000)
})
// console.log( p1 );// Promise {state: 'fulfilled', result: 123}
// 情况1:当then执行时,状态已经改变
p1.then(// then方法是同步执行
    (res)=>{// 成功的回调 fnResolve 异步执行
        console.log( 'p1成功的回调',res );
        return res;
    },
    (res)=>{// 失败的回调 fnReject 异步执行
        console.log( 'p1失败的回调',res );
        return res;
        // throw res;
    }
)// p2
.then(
    (res)=>{// 成功的回调 fnResolve 异步执行
        console.log( 'p2成功的回调',res );
    },
    (res)=>{// 失败的回调 fnReject 异步执行
        console.log( 'p2失败的回调',res );
    }
);


</script>
</body>
</html>